<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</head>
<body>
  <button id="btnPost">发起POST请求</button>  
<script>
   document.querySelector('#btnPost').addEventListener('click',async function(){
    //如果调用某个方法的返回值是Promise实例，则前面可以添加await!
    //await 只能用在被async“修饰”的方法中
    const result=await axios({
        method:'POST',
        url:'http://www.liulongbin.top:3006/api/post',
        data:{
            name:'xiaoxi',
            age:20
        }
    })
    // .then(function(result){
    //     console.log(result);
    // })
    console.log(result);
   })
</script>
</body>
</html> 